Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
HTML getting json content from iframe with src="somejsonfile.json"

i'm trying to read "local" files inside my directory with vanilla javascript inside a html. Since AJAX does not work because of CORS policy - can't read local files from a browser, I "outsmart" them using iframe which supplemented with json files that I want to read.

The problem is - I managed to get the iframe but don't know how to extract the "data" from this iframe.

chrome console

Javascript:

fileframe = document.getElementById("jsonfile");
fileframe.setAttribute("src", "test.json");
console.log(fileframe);

Chrome console output

<iframe id="jsonfile" src="test.json" style="display:none">
#document
<html>
<head>
<meta name="color-scheme" content="light dark">
 </head>
  <body>
   <pre style="word-wrap: break-word; white-space: pre-wrap;">{
"content": "thisisacontent"
   }</pre>
  </body>
 </html>
</iframe>

The data i want to get is the {"content" : "thisisacontent"} a newbie programmer here, any help will be appreciated! thanks!!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda